<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>php入门笔记 | 学途路漫漫</title><meta name="author" content="学途路漫漫"><meta name="copyright" content="学途路漫漫"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="服务器认识软件架构  C&#x2F;S (客户端-&gt;服务端) B&#x2F;S (浏览器-&gt;服务端) 客户端：资源受益方 服务端：资源提供方    开发网站的技术：php、jsp、asp、ruby、python、nodejs、c&#x2F;c++等 集成开发环境:  WAMP架构：windows+apache+mysql+php LAMP架构：Linux+apache+mysql+ph">
<meta property="og:type" content="article">
<meta property="og:title" content="php入门笔记">
<meta property="og:url" content="http://example.com/2020/06/05/php%E5%85%A5%E9%97%A8%E7%AC%94%E8%AE%B0/index.html">
<meta property="og:site_name" content="学途路漫漫">
<meta property="og:description" content="服务器认识软件架构  C&#x2F;S (客户端-&gt;服务端) B&#x2F;S (浏览器-&gt;服务端) 客户端：资源受益方 服务端：资源提供方    开发网站的技术：php、jsp、asp、ruby、python、nodejs、c&#x2F;c++等 集成开发环境:  WAMP架构：windows+apache+mysql+php LAMP架构：Linux+apache+mysql+ph">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2023/04/03/pph4qeO.jpg">
<meta property="article:published_time" content="2020-06-05T08:27:40.000Z">
<meta property="article:modified_time" content="2023-04-03T11:30:39.457Z">
<meta property="article:author" content="学途路漫漫">
<meta property="article:tag" content="php">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2023/04/03/pph4qeO.jpg"><link rel="shortcut icon" href="/img/avatar.gif"><link rel="canonical" href="http://example.com/2020/06/05/php%E5%85%A5%E9%97%A8%E7%AC%94%E8%AE%B0/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'php入门笔记',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-04-03 19:30:39'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.gif" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">7</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">8</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s1.ax1x.com/2023/04/03/pph4qeO.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="学途路漫漫"></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">php入门笔记</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-06-05T08:27:40.000Z" title="发表于 2020-06-05 16:27:40">2020-06-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-03T11:30:39.457Z" title="更新于 2023-04-03 19:30:39">2023-04-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%90%8E%E7%AB%AF/PHP/">PHP</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="php入门笔记"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="服务器认识"><a href="#服务器认识" class="headerlink" title="服务器认识"></a>服务器认识</h2><p>软件架构</p>
<ul>
<li>C&#x2F;S (客户端-&gt;服务端)</li>
<li>B&#x2F;S (浏览器-&gt;服务端)<ul>
<li>客户端：资源受益方</li>
<li>服务端：资源提供方</li>
</ul>
</li>
</ul>
<p>开发网站的技术：php、jsp、asp、ruby、python、nodejs、c&#x2F;c++等</p>
<p>集成开发环境:</p>
<ul>
<li>WAMP架构：windows+apache+mysql+php</li>
<li>LAMP架构：Linux+apache+mysql+php</li>
<li>LNMP架构：Linux+nginx+mysql+php<ul>
<li>apache：对外开放你的某一个磁盘</li>
</ul>
</li>
</ul>
<p>PHPnow：apache+mysql+php</p>
<h2 id="PHP简介"><a href="#PHP简介" class="headerlink" title="PHP简介"></a>PHP简介</h2><ul>
<li>特点：<ol>
<li>PHP（Hypertext Preprocessor）超文本预处理器：是一种通用开源脚本语言</li>
<li>PHP脚本在服务器上运行，文件后缀名为.php</li>
<li>PHP可以在不同平台上运行（windows、Linux、Unix、Mac等）</li>
<li>PHP与目前几乎所有的正在被使用的服务器兼容(Apache、IIS等)</li>
<li>PHP提供了广泛的数据库支持</li>
<li>PHP免费，官网（<a target="_blank" rel="noopener" href="http://www.php.net)/">www.php.net）</a></li>
<li>PHP易于学习且运行高效</li>
<li>严格语法</li>
</ol>
</li>
</ul>
<h2 id="一些PHP的简单的语法"><a href="#一些PHP的简单的语法" class="headerlink" title="一些PHP的简单的语法"></a>一些PHP的简单的语法</h2><h3 id="1-php输出"><a href="#1-php输出" class="headerlink" title="1.php输出"></a>1.php输出</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="title function_ invoke__">header</span>(<span class="string">&#x27;content-type:text/html;charset=&quot;utf-8&#x27;</span>);<span class="comment">//头文件声明编码格式</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">        php输出函数</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">//往页面写入内容 标签会被解析 不会覆盖之前的内容</span></span><br><span class="line">    <span class="keyword">echo</span> <span class="string">&quot;&lt;h1&gt;hello world&lt;/h1&gt;&quot;</span>;</span><br><span class="line">    <span class="title function_ invoke__">print_r</span>(<span class="string">&quot;&lt;h1&gt;hello world&lt;/h1&gt;&quot;</span>);</span><br><span class="line">	<span class="keyword">print</span> <span class="string">&quot;数字是：<span class="subst">$x</span>&lt;br&gt;&quot;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//类似于console.log() 一般用于测试程序</span></span><br><span class="line">    <span class="title function_ invoke__">var_dump</span>(<span class="number">100</span>);<span class="comment">// int(100) </span></span><br><span class="line">    <span class="title function_ invoke__">var_dump</span>(<span class="string">&quot;hello&quot;</span>);<span class="comment">// string(5) &quot;hello&quot;</span></span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="2-变量和数据类型"><a href="#2-变量和数据类型" class="headerlink" title="2.变量和数据类型"></a>2.变量和数据类型</h3><ul>
<li><p>变量定义规则</p>
<ul>
<li>变量以$符开始，后面跟变量名称</li>
<li>变量名必须以字母或学习开始</li>
<li>变量名只能包含字母数字下划线</li>
<li>变量名不能有空格</li>
<li>变量名区分大小写</li>
</ul>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="title function_ invoke__">header</span>(<span class="string">&#x27;content-type:text/html;charset=&quot;utf-8&#x27;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">        声明变量</span></span><br><span class="line"><span class="comment">         - 弱引用 赋值什么类型就是什么类型数据</span></span><br><span class="line"><span class="comment">        数据类型：</span></span><br><span class="line"><span class="comment">         字符串String 整形Integer 浮点型Float 布尔Boolean</span></span><br><span class="line"><span class="comment">         数组Array 对象Object 空的NULL</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">    <span class="variable">$username</span>=<span class="string">&quot;钢铁侠&quot;</span>;</span><br><span class="line">    <span class="variable">$age</span>=<span class="number">18</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">        字符串拼接用 .</span></span><br><span class="line"><span class="comment">        或者用占位符 &#123;变量/表达式&#125;</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">echo</span> <span class="string">&quot;我是&quot;</span>.<span class="variable">$username</span>.<span class="string">&quot;今年&quot;</span>.<span class="variable">$age</span>.<span class="string">&quot;岁&quot;</span>;</span><br><span class="line">    <span class="keyword">echo</span> <span class="string">&quot;我是<span class="subst">&#123;$username&#125;</span>今年<span class="subst">&#123;$age&#125;</span>岁&quot;</span></span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="3-条件语句"><a href="#3-条件语句" class="headerlink" title="3.条件语句"></a>3.条件语句</h3><h4 id="3-1-分支语句"><a href="#3-1-分支语句" class="headerlink" title="3.1.分支语句"></a>3.1.分支语句</h4><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="title function_ invoke__">header</span>(<span class="string">&#x27;content-type:text/html;charset=&quot;utf-8&#x27;</span>);   </span><br><span class="line">    <span class="variable">$isYes</span>=<span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span>(<span class="variable">$isYes</span>)&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">&quot;是&quot;</span>;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">&quot;否&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="3-2-switch语句"><a href="#3-2-switch语句" class="headerlink" title="3.2.switch语句"></a>3.2.switch语句</h4><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="variable">$num</span> =<span class="number">2</span>;</span><br><span class="line">    <span class="keyword">switch</span>(<span class="variable">$num</span>)&#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">            <span class="keyword">echo</span> <span class="string">&quot;数字1&quot;</span>;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">            <span class="keyword">echo</span> <span class="string">&quot;数字2&quot;</span>;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">default</span>:</span><br><span class="line">            <span class="keyword">echo</span> <span class="string">&quot;输入错误&quot;</span>;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="3-3-循环"><a href="#3-3-循环" class="headerlink" title="3.3.循环"></a>3.3.循环</h4><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">	<span class="keyword">for</span>(<span class="variable">$x</span>=<span class="number">0</span>;<span class="variable">$x</span>&lt;=<span class="number">10</span>;<span class="variable">$x</span>++)&#123;</span><br><span class="line">        <span class="keyword">print</span> <span class="string">&quot;数字是：<span class="subst">$x</span>&lt;br&gt;&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="4-函数"><a href="#4-函数" class="headerlink" title="4.函数"></a>4.函数</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">printHello</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">print</span> <span class="string">&quot;hello world&lt;br/&gt;&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="title function_ invoke__">printHello</span>();</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="5-数组"><a href="#5-数组" class="headerlink" title="5.数组"></a>5.数组</h3><ul>
<li><p>PHP有三种类型的数组</p>
<ul>
<li><p>数值&#x2F;索引数组：下标是数字</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="title function_ invoke__">header</span>(<span class="string">&#x27;content-type:text/html;charset=&quot;utf-8&#x27;</span>);   </span><br><span class="line">    <span class="variable">$cars</span>=<span class="keyword">array</span>(<span class="string">&quot;大众&quot;</span>,<span class="string">&quot;别克&quot;</span>,<span class="string">&quot;奔驰&quot;</span>);</span><br><span class="line">    <span class="title function_ invoke__">var_dump</span>(<span class="variable">$cars</span>);</span><br><span class="line">    <span class="comment">//array(3) &#123; [0]=&gt; string(6) &quot;大众&quot; [1]=&gt; string(6) &quot;别克&quot; [2]=&gt; string(6) &quot;奔驰&quot; &#125; 别克</span></span><br><span class="line">    <span class="keyword">echo</span> <span class="variable">$cars</span>[<span class="number">1</span>];<span class="comment">//别克</span></span><br><span class="line">    <span class="keyword">for</span>(<span class="variable">$i</span>=<span class="number">0</span>;<span class="variable">$i</span>&lt;<span class="title function_ invoke__">count</span>(<span class="variable">$cars</span>);<span class="variable">$i</span>++)&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">&quot;下标：<span class="subst">&#123;$i&#125;</span>,数据：<span class="subst">&#123;$cars[$i]&#125;</span>&lt;br/&gt;&quot;</span>;</span><br><span class="line">        <span class="comment">/*</span></span><br><span class="line"><span class="comment">        下标：0,数据：大众</span></span><br><span class="line"><span class="comment">        下标：1,数据：别克</span></span><br><span class="line"><span class="comment">        下标：2,数据：奔驰</span></span><br><span class="line"><span class="comment">        */</span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>关联数组：带指定键的数组，每个键关联一个值（类似map）</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="title function_ invoke__">header</span>(<span class="string">&#x27;content-type:text/html;charset=&quot;utf-8&#x27;</span>);   </span><br><span class="line">    <span class="variable">$arr</span>=<span class="keyword">array</span>(<span class="string">&quot;王五&quot;</span>=&gt;<span class="string">&quot;打渔&quot;</span>,<span class="string">&quot;张三&quot;</span>=&gt;<span class="string">&quot;种地&quot;</span>,<span class="string">&quot;李四&quot;</span>=&gt;<span class="string">&quot;打猎&quot;</span>);</span><br><span class="line">    <span class="title function_ invoke__">var_dump</span>(<span class="variable">$arr</span>);</span><br><span class="line">    <span class="comment">//array(2) &#123; [&quot;王五&quot;]=&gt; string(6) &quot;打渔&quot; [&quot;李四&quot;]=&gt; string(6) &quot;打猎&quot; &#125;</span></span><br><span class="line">    <span class="keyword">foreach</span>(<span class="variable">$arr</span> <span class="keyword">as</span> <span class="variable">$key</span> =&gt; <span class="variable">$value</span>)&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">&quot;下标：<span class="subst">&#123;$key&#125;</span>,数据：<span class="subst">&#123;$value&#125;</span>&lt;br/&gt;&quot;</span>;</span><br><span class="line">        <span class="comment">/*</span></span><br><span class="line"><span class="comment">        下标：王五,数据：打渔</span></span><br><span class="line"><span class="comment">        下标：张三,数据：种地</span></span><br><span class="line"><span class="comment">        下标：李四,数据：打猎</span></span><br><span class="line"><span class="comment">        */</span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>多维数组：索引数组和关联数组结合</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="title function_ invoke__">header</span>(<span class="string">&#x27;content-type:text/html;charset=&quot;utf-8&#x27;</span>);   </span><br><span class="line">    <span class="variable">$arr</span> = <span class="keyword">array</span>(</span><br><span class="line">        <span class="keyword">array</span>(<span class="string">&quot;name&quot;</span>=&gt;<span class="string">&quot;小白&quot;</span>,<span class="string">&quot;英语&quot;</span>=&gt;<span class="number">100</span>,<span class="string">&quot;数学&quot;</span>=&gt;<span class="number">50</span>),</span><br><span class="line">        <span class="keyword">array</span>(<span class="string">&quot;name&quot;</span>=&gt;<span class="string">&quot;小花&quot;</span>,<span class="string">&quot;英语&quot;</span>=&gt;<span class="number">60</span>,<span class="string">&quot;数学&quot;</span>=&gt;<span class="number">100</span>),</span><br><span class="line">        <span class="keyword">array</span>(<span class="string">&quot;name&quot;</span>=&gt;<span class="string">&quot;小红&quot;</span>,<span class="string">&quot;英语&quot;</span>=&gt;<span class="number">100</span>,<span class="string">&quot;数学&quot;</span>=&gt;<span class="number">100</span>)</span><br><span class="line">    );</span><br><span class="line">    <span class="keyword">for</span>(<span class="variable">$i</span>=<span class="number">0</span>;<span class="variable">$i</span>&lt;<span class="title function_ invoke__">count</span>(<span class="variable">$arr</span>);<span class="variable">$i</span>++)&#123;</span><br><span class="line">        <span class="title function_ invoke__">var_dump</span>(<span class="variable">$arr</span>[<span class="variable">$i</span>].<span class="string">&quot;&lt;br/&gt;&quot;</span>);</span><br><span class="line">        <span class="comment">/*</span></span><br><span class="line"><span class="comment">             string(10) &quot;Array</span></span><br><span class="line"><span class="comment">             &quot; string(10) &quot;Array</span></span><br><span class="line"><span class="comment">             &quot; string(10) &quot;Array</span></span><br><span class="line"><span class="comment">             &quot;</span></span><br><span class="line"><span class="comment">        */</span> </span><br><span class="line">        <span class="keyword">echo</span> <span class="variable">$arr</span>[<span class="number">2</span>][<span class="string">&quot;数学&quot;</span>];<span class="comment">//100</span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>全局数组  </p>
<ul>
<li>$_GET：接收通过get提交过来的所有数据</li>
<li>$_POST：接收通过post提交过来的所有数据</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="6-数组函数"><a href="#6-数组函数" class="headerlink" title="6.数组函数"></a>6.数组函数</h3><ul>
<li>array_keys()：返回数组中所有键名</li>
<li>array_pop()：删除数组中最后一个元素（出栈）</li>
<li>array_push()：将一个或多个元素插入数组的末尾（入栈）</li>
<li>array_rand()：从数组中随机选出一个或多个元素，返回键名</li>
<li>array_shift()：删除数组中第一个元素并返回删除元素的值</li>
<li>count()：返回数组中元素的数目</li>
<li>in_array()：检查数组中是否存在指定的值</li>
</ul>
<h3 id="7-字符串函数"><a href="#7-字符串函数" class="headerlink" title="7.字符串函数"></a>7.字符串函数</h3><ul>
<li>explode()：字符串打散为数组</li>
<li>implode()：返回一个由数组元素组合成的字符串</li>
<li>join() implode()：合并成数组</li>
<li>trim()：去掉字符串两边的字符</li>
<li>md5()：计算字符串的MD5散列</li>
<li>str_replace()：替换字符串中的一些字符(大小写敏感)</li>
</ul>
<h3 id="8-事件函数"><a href="#8-事件函数" class="headerlink" title="8.事件函数"></a>8.事件函数</h3><ul>
<li>date()：获取当前的日期</li>
<li>dote(‘Y-m-d H:i:s’)：获取当前日期，格式化</li>
<li>time()：获取时间戳</li>
<li>strtotime(‘2017-01-01 0:0:0’)：字符串转换成时间戳</li>
<li>getdate()：返回某个时间戳或者当前本地的日期&#x2F;时间的日期&#x2F;时间信息</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">学途路漫漫</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2020/06/05/php%E5%85%A5%E9%97%A8%E7%AC%94%E8%AE%B0/">http://example.com/2020/06/05/php%E5%85%A5%E9%97%A8%E7%AC%94%E8%AE%B0/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">学途路漫漫</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/php/">php</a></div><div class="post_share"><div class="social-share" data-image="https://s1.ax1x.com/2023/04/03/pph4qeO.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.png" target="_blank"><img class="post-qr-code-img" src="/img/wechat.png" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="/img/alipay.png" target="_blank"><img class="post-qr-code-img" src="/img/alipay.png" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/06/22/Cookie%E6%9C%AC%E5%9C%B0%E5%AD%98%E5%82%A8/" title="Cookie本地存储"><img class="cover" src="https://s1.ax1x.com/2023/04/03/pph4Ysf.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Cookie本地存储</div></div></a></div><div class="next-post pull-right"><a href="/2020/05/07/JavaScript%E5%85%A5%E9%97%A8%E7%AC%94%E8%AE%B0/" title="JavaScript入门"><img class="cover" src="https://s1.ax1x.com/2023/04/03/pph4Wo4.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">JavaScript入门</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.gif" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">学途路漫漫</div><div class="author-info__description">今日事，今日毕</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">7</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">8</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/code-jay" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:1940879828@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://music.163.com/#/user/home?id=306898885" target="_blank" title="Music"><i class="fa-solid fa-music"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%AE%A4%E8%AF%86"><span class="toc-number">1.</span> <span class="toc-text">服务器认识</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PHP%E7%AE%80%E4%BB%8B"><span class="toc-number">2.</span> <span class="toc-text">PHP简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E4%BA%9BPHP%E7%9A%84%E7%AE%80%E5%8D%95%E7%9A%84%E8%AF%AD%E6%B3%95"><span class="toc-number">3.</span> <span class="toc-text">一些PHP的简单的语法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-php%E8%BE%93%E5%87%BA"><span class="toc-number">3.1.</span> <span class="toc-text">1.php输出</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%8F%98%E9%87%8F%E5%92%8C%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">3.2.</span> <span class="toc-text">2.变量和数据类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E6%9D%A1%E4%BB%B6%E8%AF%AD%E5%8F%A5"><span class="toc-number">3.3.</span> <span class="toc-text">3.条件语句</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#3-1-%E5%88%86%E6%94%AF%E8%AF%AD%E5%8F%A5"><span class="toc-number">3.3.1.</span> <span class="toc-text">3.1.分支语句</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-switch%E8%AF%AD%E5%8F%A5"><span class="toc-number">3.3.2.</span> <span class="toc-text">3.2.switch语句</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-3-%E5%BE%AA%E7%8E%AF"><span class="toc-number">3.3.3.</span> <span class="toc-text">3.3.循环</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E5%87%BD%E6%95%B0"><span class="toc-number">3.4.</span> <span class="toc-text">4.函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-%E6%95%B0%E7%BB%84"><span class="toc-number">3.5.</span> <span class="toc-text">5.数组</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-%E6%95%B0%E7%BB%84%E5%87%BD%E6%95%B0"><span class="toc-number">3.6.</span> <span class="toc-text">6.数组函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%87%BD%E6%95%B0"><span class="toc-number">3.7.</span> <span class="toc-text">7.字符串函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-%E4%BA%8B%E4%BB%B6%E5%87%BD%E6%95%B0"><span class="toc-number">3.8.</span> <span class="toc-text">8.事件函数</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/03/10/vue3%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B/" title="vue3快速上手"><img src="https://user-images.githubusercontent.com/499550/93624428-53932780-f9ae-11ea-8d16-af949e16a09f.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="vue3快速上手"/></a><div class="content"><a class="title" href="/2023/03/10/vue3%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B/" title="vue3快速上手">vue3快速上手</a><time datetime="2023-03-10T06:20:40.000Z" title="发表于 2023-03-10 14:20:40">2023-03-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/12/01/laravel%E6%A1%86%E6%9E%B6%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" title="laravel框架学习笔记"><img src="https://s1.ax1x.com/2023/04/03/pph4doQ.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="laravel框架学习笔记"/></a><div class="content"><a class="title" href="/2020/12/01/laravel%E6%A1%86%E6%9E%B6%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" title="laravel框架学习笔记">laravel框架学习笔记</a><time datetime="2020-12-01T12:06:29.000Z" title="发表于 2020-12-01 20:06:29">2020-12-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/06/25/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" title="git常用命令"><img src="https://s1.ax1x.com/2023/04/03/pph46yV.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="git常用命令"/></a><div class="content"><a class="title" href="/2020/06/25/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" title="git常用命令">git常用命令</a><time datetime="2020-06-25T08:00:29.000Z" title="发表于 2020-06-25 16:00:29">2020-06-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/06/22/Cookie%E6%9C%AC%E5%9C%B0%E5%AD%98%E5%82%A8/" title="Cookie本地存储"><img src="https://s1.ax1x.com/2023/04/03/pph4Ysf.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Cookie本地存储"/></a><div class="content"><a class="title" href="/2020/06/22/Cookie%E6%9C%AC%E5%9C%B0%E5%AD%98%E5%82%A8/" title="Cookie本地存储">Cookie本地存储</a><time datetime="2020-06-22T07:47:29.000Z" title="发表于 2020-06-22 15:47:29">2020-06-22</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/06/05/php%E5%85%A5%E9%97%A8%E7%AC%94%E8%AE%B0/" title="php入门笔记"><img src="https://s1.ax1x.com/2023/04/03/pph4qeO.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="php入门笔记"/></a><div class="content"><a class="title" href="/2020/06/05/php%E5%85%A5%E9%97%A8%E7%AC%94%E8%AE%B0/" title="php入门笔记">php入门笔记</a><time datetime="2020-06-05T08:27:40.000Z" title="发表于 2020-06-05 16:27:40">2020-06-05</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 学途路漫漫</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>